package AbandonedDogPractice;

import java.util.Scanner;

public class Dog_v1 {
	
	private static final String title = "DB연동 유기견 관리 프로그램";
	private static final String menu = " 추가 (1) 조회 (2) 변경 (3) 삭제 (4) 종료 (0) ";
	private static final String addmsg = " 강아지 정보 no, name, sex, type, age, regdate, collar, fno, storedloc, etc, mercykilling 순으로 눌러보세요 ";
	private static final String modmsg1 = " 수정할 데이터 번호를 입력하세요 ";
	private static final String modmsg2 = " 수정핧 데이터를 name, sex, type, age, regdate, collar, fno, storedloc, etc, mercykilling 순으로 눌러보세요 ";
	private static final String delmsg = " 삭제할 데이터 번호를 입력하시오 ";
	
	public static void main(String[] args) {
		
		JDBCDogPractice dog = new JDBCDogPractice();
		Scanner sc = new Scanner(System.in);
		
		while(true) {
			System.out.println( title );
			System.out.println( menu );
			switch (sc.nextInt()) {
			case 0 : sc.close();
			System.exit(0);
			break;
			case 1 : addDog(sc, dog);
					 break;
			case 2 : showDog(dog);
					 break;
			case 3 : modifyDog(sc, dog);
					 break;
			case 4 : removeDog(sc, dog);
					 break;
			}
		}
	}
	
	private static void removeDog(Scanner sc, JDBCDogPractice dog) {
		System.out.println( dog.readDog() );
		System.out.println( delmsg );
		int dogNo = sc.nextInt();
		if (dog.removeDog(dogNo));
		System.out.println( "성공적으로 데이터 삭제됨!" );
		
	}

	private static void modifyDog(Scanner sc, JDBCDogPractice dog) {
		System.out.println( dog.readDog() );
		System.out.println( modmsg1 );
		int dogNo = sc.nextInt();
		System.out.println( modmsg2 );
		DogVOPractice dg = new DogVOPractice(sc.nextInt(), sc.next(), sc.next(), sc.nextInt(), sc.nextInt(), sc.next(), sc.nextInt(), sc.nextInt(), sc.next(), sc.next(), sc.hasNext());
		dg.setDogNo(dogNo);
		if (dog.modifyDog(dg))
		{ System.out.println( "성공적으로 데이터 수정!" ); }
	}

	private static void showDog(JDBCDogPractice dog) {
		System.out.println( dog.readDog() );
	}

	public static void addDog ( Scanner sc, JDBCDogPractice dog ) {
		System.out.println(addmsg);
		DogVOPractice dg = new DogVOPractice( sc.nextInt(), sc.next(), sc.next(), sc.nextInt(), sc.nextInt(), sc.next(), sc.nextInt(), sc.nextInt(), sc.next(), sc.next(), sc.equals(sc) );
	}

}
